package com.efuture.servlet.serveletcontext;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;

/**
 * @description: 演示获取servletContext对象
 * @author zhaoshanshan
 * @date 2021/10/3 12:10 上午
 * @version 1.0
 */
@WebServlet("/GetServletContext")
public class GetServletContext extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //ServletContext servletContext = request.getServletContext();//第一种方式
        ServletContext servletContext = this.getServletContext();//第二种方式
        //两种方式获取的ServletContext对象都是同一个
        System.out.println(servletContext);

    }
}
